// get user info
import {
  addList,
  deleteList,
  getProductById,
  page,
  updateList,
  addCart,
  getIndex,
  getSelect,
  getCartById, uploadFile
} from '@/api/product'

const actions = {
  // 这里是get商品信息
  getList({ commit }, data) {
    return new Promise((resolve, reject) => {
      page(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里是add商品信息
  addList({ commit }, data) {
    return new Promise((resolve, reject) => {
      addList(data).then(response => {
        console.log(response)
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里是修改商品信息
  UpdateList({ commit }, data) {
    return new Promise((resolve, reject) => {
      updateList(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里是上传文件信息
  uploadFile({ commit }, data) {
    return new Promise((resolve, reject) => {
      uploadFile(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里删除商品信息
  DeleteList({ commit }, data) {
    return new Promise((resolve, reject) => {
      deleteList(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里是get商品信息byID
  getById({ commit }, data) {
    return new Promise((resolve, reject) => {
      getProductById(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 这里是下单时的get商品信息byID
  getCardById({ commit }, data) {
    return new Promise((resolve, reject) => {
      getCartById(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加商品到购物车
  addCart({ commit }, data) {
    return new Promise((resolve, reject) => {
      addCart(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getIndex({ commit }) {
    return new Promise((resolve, reject) => {
      getIndex().then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getIndexSelect({ commit }) {
    return new Promise((resolve, reject) => {
      getSelect().then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
export default {
  namespaced: true,
  actions
}
